﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;

namespace OPTFleet.Data
{
    public class Conexao
    {
        private static String connectionString;
        private DbConnectionStringBuilder dbcstringbuilder;

        private DbConnection connection;
        
        public DbConnection Connection
        {
            get { return connection; }
            set { connection = value; }
        }

        public Conexao()
        {
            dbcstringbuilder = new DbConnectionStringBuilder();
            string dir = Directory.GetCurrentDirectory();
            //connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename="+"C:\\Users\\Catamy\\Desktop"+"\\OPTFleetDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            //connectionString = "Data Source=sql2003.shared-servers.com,1089;Initial Catalog=OPTFleet;Persist Security Info=True;User ID=optfleet;Password=c4rr410";
            connectionString = "Data Source="+".\\SQLEXPRESS;AttachDbFilename=C:\\Users\\no-skill\\Documents\\Visual Studio 2010\\Projects\\OPTFleet\\WindowsFormsApplication1\\bin\\Debug\\OPTFleet_Data.mdf"+";Integrated Security=True;Connect Timeout=30;User Instance=True";
        }

        public void connect()
        {
            dbcstringbuilder.ConnectionString = connectionString;
            connection = new SqlConnection(dbcstringbuilder.ConnectionString);

            connection.Open();
        }

        public void disconnect()
        {
            connection.Close();
        }
    }
}
